package cn.ffcs.unm.userDefinedRecord.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.stereotype.Repository;

import cn.ffcs.unm.userDefinedRecord.dao.UserDefinedRecordDao;
import cn.ffcs.unm.userDefinedRecord.model.UserDefinedRecord;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("userDefinedRecordDao")
public class UserDefinedRecordDaoImpl extends BaseDaoImpl implements UserDefinedRecordDao {

	@Override
	public PageInfo queryPageInfoByUserDefinedRecord(UserDefinedRecord userDefinedRecord, int currentPage, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" select distinct ");
		sb.append(" ja1.MONTH_ID  monthId,ja1.UNIT_ID  单位编码,ja1.CODE  code,ja1.CREATIONTIME  creationTime, ");
		sb.append("ja1.DATAORIGINFLAG  dataOriginFlag,ja1.DATATYPE  dataType,ja1.DR  删除类型, ");
		sb.append("decode(JA1.enablestate,'1','未启用','2','已启用','3','已停用') enableState ,ja1.INNERCODE  innerCode,");
		sb.append("ja1.MEMO  memo,ja1.MNECODE  mneCode,ja1.MODIFIEDTIME  modifiedTime,ja1.NAME  name,ja2.name upName, ");
		sb.append("ja1.PK_DEFDOC  pkDefdoc,ja3.name listName,ja1.SHORTNAME  shortName ,ja1.TS  时间戳");
		sb.append(" from LDAPM_MPW_bd_defdoc ja1, LDAPM_MPW_bd_defdoc ja2 , LDAPM_MPW_BD_DEFDOCLIST ja3");
		sb.append(" where ja1.PID=ja2.PK_DEFDOC and ja1.PK_DEFDOCLIST=ja3.PK_DEFDOCLIST ");
		List<Object> params = new ArrayList<Object>();
		if (null != userDefinedRecord) {
			if (!StrUtil.isEmpty(userDefinedRecord.getMonthId())) {
				sb.append(" AND ja1.MONTH_ID = ? ");
				params.add(userDefinedRecord.getMonthId());
			}
			if (!StrUtil.isEmpty(userDefinedRecord.getName())) {
				sb.append(" AND JA1.NAME LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(userDefinedRecord.getName())
						+ "%");
			}
			if (!StrUtil.isEmpty(userDefinedRecord.getCode())) {
				sb.append(" AND JA1.CODE LIKE ? ");
				params.add("%"
						+ StringEscapeUtils.escapeSql(userDefinedRecord.getCode())
						+ "%");
			}
		}
		return this.jdbcFindPageInfo(sb.toString(), params, currentPage,
				pageSize, UserDefinedRecord.class);
	}

}
